﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlatformUW.Entities
{
    /// <summary>
    /// 通信协议
    /// </summary>
    public enum ProtocolEnum
    {
        /// <summary>
        /// 1.MODBUS
        /// </summary>
        Modbus = 0,
        /// <summary>
        /// 2.电源板
        /// </summary>
        Power,
        /// <summary>
        /// 3.高度计
        /// </summary>
        Altimeter,
        /// <summary>
        /// 4.深度计
        /// </summary>
        Depth,
        /// <summary>
        /// 5.摄像头
        /// </summary>
        Camera,
        /// <summary>
        /// 6.操作杆
        /// </summary>
        Joystick,
        /// <summary>
        /// 7.MODBUS TCP
        /// </summary>
        ModbusTCP,
        /// <summary>
        /// 8.云台
        /// </summary>
        PanTilt,
        /// <summary>
        /// 9.罗盘
        /// </summary>
        Compass,
        /// <summary>
        /// 10.姿态(SCM220)
        /// </summary>
        TCM3,
        /// <summary>
        /// 11.CTD
        /// </summary>
        CTD,
        /// <summary>
        ///12. 推进器
        /// </summary>
        Thruster,
        /// <summary>
        /// 13.高度计
        /// </summary>
        ISA500,
        /// <summary>
        /// 14.姿态
        /// </summary>
        LEC210,
        /// <summary>
        /// 15.二号船罗经
        /// </summary>
        Ship2_gyro,
        /// <summary>
        /// 16.二号船GPS
        /// </summary>
        Ship2_GPS,
        /// <summary>
        /// 17.二号船USBL
        /// </summary>
        Ship2_USBL,
        /// <summary>
        /// 18.网络摄像头TCP控制协议
        /// </summary>
        NetCameraTCP,
        /// <summary>
        /// 19.绝缘检测协议
        /// </summary>
        Insulation,
        /// <summary>
        /// 20.惯导
        /// </summary>
        INS,
        /// <summary>
        /// 21.SID视频字符叠加
        /// </summary>
        SDI_OSD,
        /// <summary>
        /// 22.高度计
        /// </summary>
        HDCS200,
        /// <summary>
        /// 23.PTZ相机
        /// </summary>
        PTZCam,
        /// <summary>
        /// 24.Compass 3D
        /// </summary>
        Compass3D,
        /// <summary>
        /// 25.GPS_PGPVTG数据(深拖)
        /// </summary>
        Ship2_GPVTG,
        /// <summary>
        /// 26.GPSG数据(深拖)
        /// </summary>
        DTGPS,
        /// <summary>
        /// 27.Modbus协议,只读
        /// </summary>
        ModbusReadOnly,
        /// <summary>
        /// 28.声学所6000k DVL,只读
        /// </summary>
        DVL,
        /// <summary>
        /// 29. 绞车A架状态信息只读
        /// </summary>
        Winch,
        /// <summary>
        /// 30. 招商船舶罗经信息只读
        /// </summary>
        CMI_Gyro,
        /// <summary>
        /// 31. 招商HiPAP 超短基线信标读取
        /// </summary>
        CMI_USBL,
        /// <summary>
        /// 32. 招商HiPAP 长基线信标读取
        /// </summary>
        CMI_LBL,
        /// <summary>
        /// 33. 4K相机控制
        /// </summary>
        CAM4K,
        /// <summary>
        /// 34. PDU的PLC控制
        /// </summary>
        PLC_S71200,
        /// <summary>
        /// Seapath 42 惯导
        /// </summary>
        Seapath_42
    }

    /// <summary>
    /// 通道类型
    /// </summary>
    public enum PortCategory
    {
        /// <summary>
        /// TCP通信方式
        /// </summary>
        TCP = 0,    // TCP
        /// <summary>
        /// UDP通信方式
        /// </summary>
        UDP,
        /// <summary>
        /// SERIAL通信方式
        /// </summary>
        SRIAL
    }

    /// <summary>
    /// 通信协议参数
    /// </summary>
    public class ProtocolParams
    {
        /// <summary>
        /// 索引号
        /// </summary>
        public int Index { get; set; }
        /// <summary>
        /// 协议名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 只读起始地址
        /// </summary>
        public int StartAdr_RO { get; set; }
        /// <summary>
        /// 只读数据长度
        /// </summary>
        public int RegLen_RO { get; set; }
        /// <summary>
        /// 读写起始地址
        /// </summary>
        public int StartAdr_RW { get; set; }
        /// <summary>
        /// 读写数据长度
        /// </summary>
        public int RegLen_RW { get; set; }
    }

    /// <summary>
    /// 协议数据定义
    /// </summary>
    public static class ProtocolDefine
    {
        /// <summary>
        /// 已有协议参数
        /// </summary>
        public static List<ProtocolParams> Params = new List<ProtocolParams>
        {
            new ProtocolParams{Index = 0,  Name="Modbus",    StartAdr_RO = -1, RegLen_RO = -1, StartAdr_RW = -1, RegLen_RW = -1},
            new ProtocolParams{Index = 1,  Name="Power",     StartAdr_RO = 0,  RegLen_RO = 10, StartAdr_RW = 0,  RegLen_RW = 2 },
            new ProtocolParams{Index = 2,  Name="Altimeter", StartAdr_RO = 0,  RegLen_RO = 1,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 3,  Name="Depth",     StartAdr_RO = 0,  RegLen_RO = 6, StartAdr_RW = 0, RegLen_RW = 0},
            new ProtocolParams{Index = 4,  Name="Camera",    StartAdr_RO = 0,  RegLen_RO = 0,  StartAdr_RW = 0, RegLen_RW = 11},
            new ProtocolParams{Index = 5,  Name="Joystick",  StartAdr_RO = 0,  RegLen_RO = 27, StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 6,  Name="ModbusTCP", StartAdr_RO = -1, RegLen_RO = -1, StartAdr_RW = -1, RegLen_RW = -1},
            new ProtocolParams{Index = 7,  Name="PanTilt",   StartAdr_RO = 0, RegLen_RO = 10, StartAdr_RW = 0, RegLen_RW = 10},
            new ProtocolParams{Index = 8,  Name="Compass",   StartAdr_RO = 0,  RegLen_RO = 3,  StartAdr_RW = 0,  RegLen_RW = 2 },
            new ProtocolParams{Index = 9,  Name="TCM3",      StartAdr_RO = 0,  RegLen_RO = 10, StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 10,  Name="CTD",       StartAdr_RO = 0,  RegLen_RO = 7,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 11,  Name="Thruster",  StartAdr_RO = 0,  RegLen_RO = 4,  StartAdr_RW = 0,  RegLen_RW = 2 },
            new ProtocolParams{Index = 12, Name="ISA500",    StartAdr_RO = 0,  RegLen_RO = 5, StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 13, Name="LEC210",    StartAdr_RO = 0,  RegLen_RO = 3, StartAdr_RW = 0,  RegLen_RW = 2 },
            new ProtocolParams{Index = 14, Name="Ship2_gyro",    StartAdr_RO = 0,  RegLen_RO = 2,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 15, Name="Ship2_GPS",    StartAdr_RO = 0,  RegLen_RO = 15,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 16, Name="Ship2_USBL",    StartAdr_RO = 0,  RegLen_RO = 34,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 17, Name="NetCameraTCP",    StartAdr_RO = 0,  RegLen_RO = 0,  StartAdr_RW = 0,  RegLen_RW = 30 },
            new ProtocolParams{Index = 18, Name="Insulation",    StartAdr_RO = 0,  RegLen_RO = 2,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 19, Name="INS",    StartAdr_RO = 0,  RegLen_RO = 32,  StartAdr_RW = 0,  RegLen_RW = 10 },
            new ProtocolParams{Index = 20, Name="SDI_OSD",    StartAdr_RO = 0,  RegLen_RO = 0,  StartAdr_RW = 0,  RegLen_RW = 30 },
            new ProtocolParams{Index = 21, Name="HDCS200",    StartAdr_RO = 0,  RegLen_RO = 1,  StartAdr_RW = 0,  RegLen_RW = 2 },
            new ProtocolParams{Index = 22, Name="PTZ_Cam",    StartAdr_RO = 0,  RegLen_RO = 0,  StartAdr_RW = 0,  RegLen_RW = 20 },
            new ProtocolParams{Index = 23,  Name="Compass3D",   StartAdr_RO = 0,  RegLen_RO = 3,  StartAdr_RW = 0,  RegLen_RW = 2 },
            new ProtocolParams{Index = 24,  Name="Ship2_GPVTG",   StartAdr_RO = 0,  RegLen_RO = 4,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 25,  Name="DTGPS",   StartAdr_RO = 0,  RegLen_RO = 15,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 26, Name="ModbusReadOnly",    StartAdr_RO = -1,  RegLen_RO = -1,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 27, Name="DVL",    StartAdr_RO = 0,  RegLen_RO = 30,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 28, Name="Winch",    StartAdr_RO = 0,  RegLen_RO = 5,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 29, Name="CMI_Gyro",    StartAdr_RO = 0,  RegLen_RO = 2,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 30, Name="CMI_USBL",    StartAdr_RO = 0,  RegLen_RO = 55,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 31, Name="CMI_LBL",    StartAdr_RO = 0,  RegLen_RO = 55,  StartAdr_RW = 0,  RegLen_RW = 0 },
            new ProtocolParams{Index = 32, Name="Cam_4k",    StartAdr_RO = 0,  RegLen_RO = 0,  StartAdr_RW = 0,  RegLen_RW = 10 },
            new ProtocolParams{Index = 33, Name="PLC_S71200",    StartAdr_RO = -1,  RegLen_RO = -1,  StartAdr_RW = -1,  RegLen_RW = -1 },
            new ProtocolParams{Index = 34, Name="Seapath_42",    StartAdr_RO = 0,  RegLen_RO = 20,  StartAdr_RW = 0,  RegLen_RW = 0 },
        };
    }
}
